package config

import (
	"time"

	"tlsx"

	"github.com/cloudwego/hertz/pkg/app/server"
	"github.com/cloudwego/hertz/pkg/common/tracer/stats"
	"github.com/cloudwego/hertz/pkg/network/netpoll"
	"github.com/cloudwego/hertz/pkg/protocol/suite"

	"github.com/hertz-contrib/http2/config"
	"github.com/hertz-contrib/http2/factory"
)

func NewHttp2(addr string) *server.Hertz {
	cfg := tlsx.TlsCfg(suite.HTTP3, suite.HTTP2, suite.HTTP1)
	h := server.New(
		server.WithALPN(true),
		server.WithTraceLevel(stats.LevelBase),
		server.WithAltTransport(netpoll.NewTransporter),
		server.WithTLS(cfg),
		server.WithHostPorts(addr))
	h.AddProtocol(suite.HTTP2, factory.NewServerFactory(
		config.WithReadTimeout(1*time.Millisecond),
		config.WithDisableKeepAlive(true)))
	return h
}
